<?php
/**
 * Created by PhpStorm.
 * User: u
 * Date: 2018/12/12
 * Time: 15:42
 */
namespace common\sources\read\shop;

use common\models\craftsman\Shop;

class ShopAccess implements IShopAccess
{

    public function getList($data)
    {
        $where = 'bus_id = '.$data['bus_id'];
        if(!empty($data['shop_type']))
        {
            $where .= " AND shop_type=".$data['shop_type'];
        }
        return Shop::find()
                ->select("id,bus_id,shop_name,ww_name,send_name,send_phone,pro_name,city_name,area_name,addr,home_url,audit_status")
                ->where($where)
                ->orderBy("create_time desc")
                ->asArray()
                ->all();
    }

    public function getBusinessShop($data)
    {
        return Shop::find()
            ->select("id,bus_id,shop_name,ww_name,send_name,send_phone,pro_name,city_name,area_name,addr,home_url,audit_status")
            ->where(" bus_id = ".$data['bus_id']." AND shop_type = ".$data['shop_type']." AND is_display =1 AND (audit_status = 1 or audit_status = 2)")
            ->orderBy("create_time desc")
            ->asArray()
            ->all();
    }

    public function getBusShop($data)
    {
        return Shop::find()
            ->select("id,shop_name")
            ->where(['bus_id'=>$data['bus_id'],"shop_type"=>$data['shop_type'],"audit_status" => 2, "is_display" =>1])
            ->orderBy("create_time desc")
            ->asArray()
            ->all();
    }

    public function getShopMessage($data)
    {
        return Shop::find()
            ->select("id,bus_id,shop_name,ww_name,send_name,send_phone,pro_name,city_name,area_name,addr,home_url,audit_status")
            ->where("ww_name = '".$data['ww_name']."' or  shop_name ='".$data['shop_name']."'")
            ->orderBy("create_time desc")
            ->asArray()
            ->all();
    }

    public function getShopCount($data)
    {
        return Shop::find()
            ->where("shop_type = '".$data['shop_type']."'"." AND bus_id =".$data['bus_id'])
            ->count();
    }

    public function getShopDetail($shop_id)
    {
        return Shop::find()
            ->select("id,bus_id,shop_name,ww_name,send_name,send_phone,pro_name,city_name,area_name,addr,home_url,audit_status,is_print")
            ->where(['id' => $shop_id])
            ->asArray()
            ->one();
    }

}